package com.zlq.cn.test;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.*;
import com.zlq.cn.dto.vo.ExamQuestionImport;
import com.zlq.cn.entity.ExamAnswers;
import com.zlq.cn.entity.ExamQuestions;
import com.zlq.cn.enums.QuestionTypeEnum;
import com.zlq.cn.util.StringUtils;
import okhttp3.HttpUrl;
import one.util.streamex.StreamEx;
import org.apache.commons.io.FilenameUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;

public class Demo {
    public static void main(String[] args) throws Exception {
//        ImportParams params = new ImportParams();
//        params.setTitleRows(1);
//        List<ExamQuestionImport> examQuestionImports = ExcelImportUtil.importExcel(new File("C:\\Users\\Administrator\\Desktop\\制作自己题库_EXCEL模版.xlsx"), ExamQuestionImport.class, params);

//        Workbook book = WorkbookFactory.create(new File("C:\\Users\\Administrator\\Desktop\\制作自己题库_EXCEL模版.xlsx"));
//        Row row = book.getSheetAt(0).getRow(0);
//        for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
//            String cellValue = row.getCell(i).getStringCellValue();
//            if (StringUtils.isNoneBlank(cellValue)){
//                System.out.println(cellValue);
//            }
//        }
//        String accessKeyId = "Dj6HFQZt02MIofUedpMneqxf";
//        String timestamp = LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-mm-ddThh:mm:ssZ");
//        String authStringPrefix = String.format("bce-auth-v1/%s/%s/%s", accessKeyId, timestamp, "60");
//        String baseUrl = "http://www.zuowen.com/xiaoxue/";
//        Document document = Jsoup.connect(baseUrl).get();
//        Document document = null;
//        Elements elements = null;
//        document = Jsoup.parse(FileUtil.readString("C:\\Users\\Administrator\\Desktop\\zuowen.txt", "UTF-8"));
//        elements = document.select(".taglist li:eq(0) a[target=\"_blank\"]");
//        for (Element element : elements) {
//            Element element1 = element.previousElementSibling();
//            System.out.println(element1);
//        }
        String xx = "ceshi_读后感_150字";
        System.out.println(StringUtils.substringAfterLast(xx,"_"));
        System.out.println(FilenameUtils.getBaseName("https://www.zuowen.com/e/20231202/656a90c7305bb.shtml"));
//        // https://www.zuowen.com/xiaoxue/yinianji/xieren/index_2.shtml
//        System.out.println(elements);


//        document = Jsoup.parse(FileUtil.readString("C:\\Users\\Administrator\\Desktop\\zuowen_type.txt", "UTF-8"));
//        elements = document.select(".artlist .artbox_l_t a");
//        for (Element element : elements) {
//            System.out.println(element.attr("href"));
//        }
        // https://www.zuowen.com/xiaoxue/yinianji/xieren/index_2.shtml


//        document = Jsoup.parse(FileUtil.readString("C:\\Users\\Administrator\\Desktop\\zuowen_dtl.txt", "UTF-8"));
//        elements = document.select(".con_content p:not([style])");
//        String joining = StreamEx.of(elements)
//                .map(Element::text)
//                .filter(StringUtils::isNotBlank)
//                .joining("\r\n");
//        for (Element element : elements) {
//            System.out.println(element.text());
//        }
//        System.out.println(joining);
//
//        System.out.println(StringUtils.substring("2023-12-02  来源：网络转载", 0, 10));
        // https://thirtyfairy.oss-cn-shenzhen.aliyuncs.com
//        HttpUrl httpUrl = HttpUrl.get("https://thirtyfairy.oss-cn-shenzhen.aliyuncs.com/xingainian/dierce/danciluyin/Lesson 09.mp3");
//        for (String pathSegment : httpUrl.pathSegments()) {
//            System.out.println(pathSegment);
//        }
//        System.out.println("/xingainian/dierce/donghuakecheng/lesson01.jpg".substring(1));
//        String s1 = "https://thirtyfairy.oss-cn-shenzhen.aliyuncs.com/xingainian/dierce/donghuakecheng/lesson01.mp4";

//        // Endpoint以华东1（杭州）为例，其它Region请按实际情况填写。
//        String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
//        // 从环境变量中获取访问凭证。运行本代码示例之前，请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
//        // 填写Bucket名称，例如examplebucket。
//        String bucketName = "thirtyfairy";
//        // 指定前缀，例如exampledir/object。
//        String keyPrefix = "xingainian";
//        // 设置每页列举200个文件。
//        int maxKeys = 200;
//        // 创建OSSClient实例。
//        OSS ossClient = new OSSClientBuilder().build(endpoint, "LTAI4G8SrHhzxK8Jv5tLGqYV", "uloigqCRGKCGWbP8GXCbGHl9z8NDts");
//
//        try {
//            String nextMarker = null;
//            ObjectListing objectListing;
//            do {
//                ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
//                listObjectsRequest.withMarker(nextMarker).withMaxKeys(maxKeys);
//                listObjectsRequest.setPrefix(keyPrefix);
//                objectListing = ossClient.listObjects(listObjectsRequest);
//
//                List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
//                for (OSSObjectSummary s : sums) {
//                    System.out.println(JSON.toJSONString(s));
//                }
//
//                nextMarker = objectListing.getNextMarker();
//
//            } while (objectListing.isTruncated());
//        } catch (OSSException oe) {
//            System.out.println("Caught an OSSException, which means your request made it to OSS, "
//                    + "but was rejected with an error response for some reason.");
//            System.out.println("Error Message:" + oe.getErrorMessage());
//            System.out.println("Error Code:" + oe.getErrorCode());
//            System.out.println("Request ID:" + oe.getRequestId());
//            System.out.println("Host ID:" + oe.getHostId());
//        } catch (ClientException ce) {
//            System.out.println("Caught an ClientException, which means the client encountered "
//                    + "a serious internal problem while trying to communicate with OSS, "
//                    + "such as not being able to access the network.");
//            System.out.println("Error Message:" + ce.getMessage());
//        } finally {
//            if (ossClient != null) {
//                ossClient.shutdown();
//            }
//        }
    }
}                  